package com.diaohw.module.system.obj.mapstruct;

import com.diaohw.module.system.obj.dto.SysMenuDTO;
import com.diaohw.module.system.obj.entity.SysMenuDO;
import com.diaohw.module.system.obj.vo.RouteVO;
import com.diaohw.module.system.obj.vo.SysMenuVO;
import org.mapstruct.InheritConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * 菜单管理 转换层。
 *
 * @author D-Hw
 * @since 2025-07-29 16:55:25
 */
@Mapper
public interface SysMenuMapstruct {

    SysMenuMapstruct INSTANCE = Mappers.getMapper(SysMenuMapstruct.class);

    @InheritConfiguration
    SysMenuDTO toDTO(SysMenuDO data);

    @InheritConfiguration
    List<SysMenuDTO> toDTOList(List<SysMenuDO> rows);

    @InheritConfiguration
    SysMenuDO toEntity(SysMenuDTO data);

    SysMenuVO toVO(SysMenuDO data);

    List<SysMenuVO> toVOList(List<SysMenuDO> list);

    @Mapping(target = "path", source = "sysMenuDO.routePath")
    @Mapping(target = "name", source = "sysMenuDO.routeName")
    @Mapping(target = "meta.title", source = "sysMenuDO.name")
    @Mapping(target = "meta.icon", source = "sysMenuDO.icon")
    @Mapping(target = "meta.hidden", expression = "java( sysMenuDO.getVisible() == null ? Boolean.FALSE : sysMenuDO.getVisible() == 1 )")
    @Mapping(target = "meta.keepAlive", expression = "java( sysMenuDO.getKeepAlive() == null ? Boolean.FALSE : sysMenuDO.getKeepAlive() == 1 )")
    @Mapping(target = "meta.alwaysShow", expression = "java( sysMenuDO.getAlwaysShow() == null ? Boolean.FALSE : sysMenuDO.getAlwaysShow() == 1 )")
    @Mapping(target = "meta.params", source = "sysMenuDO.params")
    @Mapping(target = "children", ignore = true)
    RouteVO toRoute(SysMenuDO sysMenuDO);


    List<RouteVO> toRouteList(List<SysMenuDO> menuList);
}
